import service from "@/utils/axios";
import store from "@/store"; // 确保正确引入 Vuex store
const gettoken = () => {
  const token = store.getters["user/gettoken"];
  return token;
};
export const userlogin = (username, password) => {
  const params = new URLSearchParams();
  params.append("username", username);
  params.append("password", password);
  return service.post("/login", params, {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
};
export const userregister = (username, password) => {
  const params = new URLSearchParams();
  params.append("username", username);
  params.append("password", password);
  return service.post("/register", params, {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
};

export const validateToken = (token) => {
  return service.get(`/user/verifytokey?token=${token}`);
};
export const gethomedata = () => {
  return service.get(`/home/gethomedata`, {
    headers: {
      Authorization: gettoken(), // 示例：携带 Authorization 请求头
    },
  });
};
